/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @authors: Pat, Jamie, Kazu, Stephen, and Shaoyan
 */
import java.sql.*;
/**
 * 
 * @authors: Pat, Jamie, Kazu, Stephen, and Shaoyan
 */
public class BookingManager {
	private int vehicleID;
	private int cancelTimeWindow;
	private int currentTime;
	private int currentDate;
	private int bookingTime;
	private int bookingDate;

        /**
         * 
         */
        public BookingManager(){
            
	}

        /**
         * 
         * @param vehicleID
         * @return
         */
        public int getVehicleStatus(int vehicleID){
		/*
		 * TODO
		 */
		return 0;
	}
        /**
         * 
         * @param customerID
         * @return
         */
        public ResultSet getBookings(int customerID){
            ResultSet info;
            Booking book = new Booking();
            info = book.getCustomerBookings(customerID);
            return info;
        }
	
        /**
         * 
         * @param customerID
         * @param pickUpDepotID
         * @param dropOffDepotID
         * @param vehicleClass
         * @param bookingDate
         * @param startTime
         * @param numHours
         * @return
         */
        public int bookVehicle(int customerID,int pickUpDepotID,int dropOffDepotID, int vehicleClass, String bookingDate, int startTime, int numHours){
		Vehicle vehicle = new Vehicle();
                int status = 0;
                int vehicleID;
                vehicleID = vehicle.getAvailableVehicle(pickUpDepotID, vehicleClass, Date.valueOf(bookingDate), startTime, (startTime + numHours));
                System.out.println("Available vehicle id= "+vehicleID);
                if(vehicleID != -1){
                    Booking book = new Booking();
                    status = book.addBooking(customerID, vehicleID, pickUpDepotID,dropOffDepotID, vehicleClass, bookingDate, startTime,(startTime+numHours));
                    if (status == 1)
                    {
                           Customer cust = new Customer();
                           cust.updateHours(customerID, (numHours*-1));
                    }
                } else
                    status = -3;
		return status;
	}
        
        /**
         * 
         * @param bookID
         * @return
         */
        public int checkVoliation(int bookID){
            Booking book = new Booking();
            return book.checkCancelRights(bookID);
        }
        
        /**
         * 
         * @param bookID
         */
        public void removeBooking(int bookID){
            Booking book = new Booking();
            book.removeBooking(bookID);
        }
        
        /**
         * 
         * @param vehicleId
         * @param bookingDate
         * @param startTime
         * @param numHours
         * @return
         */
        public int bookForMaintenance(int vehicleId, String bookingDate, int startTime, int numHours) {
            int status = 0;
            Booking book = new Booking();
            boolean vehicleBooked = book.isVehicleBooked(vehicleId, bookingDate, startTime, (startTime+numHours));
            if (!vehicleBooked) {
                status = book.addBooking(0, vehicleId, 1, 1, 1, bookingDate,startTime,(startTime+numHours));
            }
            return status;
        }

}
